package com.example.dell.guidepro0718xubowen.acitivity;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.dell.guidepro0718xubowen.R;
import com.example.dell.guidepro0718xubowen.bean.WeatherInfo;
import com.example.dell.guidepro0718xubowen.listener.WeatherListener;
import com.example.dell.guidepro0718xubowen.mode0718xubowen.WeatherMode;

import static android.R.attr.button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,WeatherListener{
    EditText editCityNumber;
    Button button_ch,button_51;
    TextView textCityName,textTemp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    void initView(){//初始化控件
        editCityNumber=(EditText)findViewById(R.id.edit_cityNumber);
        button_ch=(Button)findViewById(R.id.button_ch);
        button_51=(Button)findViewById(R.id.button_51);
        textCityName=(TextView)findViewById(R.id.text_cityName);
        textTemp=(TextView)findViewById(R.id.text_temp);
        button_ch.setOnClickListener(this);
        button_51.setOnClickListener(this);


         }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_ch:
                WeatherMode mode=new WeatherMode();
                mode.getWeather(editCityNumber.getText().toString(),this);

                break;
            case R.id.button_51:
                /////////
                break;

        }


    }

    @Override
    public void onResponse(WeatherInfo weatherInfo) {
        textCityName.setText(weatherInfo.getCity());
        textTemp.setText(weatherInfo.getTemp());
    }

    @Override
    public void onFailure(String msg) {
     textCityName.setText(msg);
    }
}
